#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10, M = N << 1;
int n;
int h[N], e[M], w[M], ne[M], idx;
int f1[N], f2[N], res;
void add(int a, int b, int c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
// 这个dfs到叶节点会返回
void dfs(int u, int parent) {
  f1[u] = f2[u] = 0;
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    if (j == parent) continue;
    dfs(j, u);
    if (f1[j] + w[i] > f1[u]) {
      f2[u] = f1[u];         // 次长路径
      f1[u] = f1[j] + w[i];  // 最长路径
    } else if (f1[j] + w[i] > f2[u]) {
      f2[u] = f1[j] + w[i];  // 次长路径
    }
  }
  res = max(res, f1[u] + f2[u]);
}
int main() {
  memset(h, -1, sizeof h);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    add(a, b, c);
    add(b, a, c);
  }
  dfs(1, -1);
  cout << res << endl;
  return 0;
}
